package com.hhhn.wk.text;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.hhhn.wk.R;
import com.hhhn.wk.base.BaseActivity;
import com.hhhn.wk.widget.select_address.bean.City;
import com.hhhn.wk.widget.select_address.bean.County;
import com.hhhn.wk.widget.select_address.bean.Province;
import com.hhhn.wk.widget.select_address.bean.Street;
import com.hhhn.wk.widget.select_address.utils.LogUtil;
import com.hhhn.wk.widget.select_address.widget.AddressSelector;
import com.hhhn.wk.widget.select_address.widget.BottomDialog;
import com.hhhn.wk.widget.select_address.widget.OnAddressSelectedListener;
import com.hhhn.wk.utils.ToastUtils;
import com.hhhn.wk.widget.dialog.DelDialog;

public class TextFrameActivity extends BaseActivity implements View.OnClickListener, OnAddressSelectedListener, AddressSelector.OnDialogCloseListener, AddressSelector.onSelectorAreaPositionListener {
    private TextView tv_selector_area;
    private BottomDialog dialog;
    private String provinceCode;
    private String cityCode;
    private String countyCode;
    private String streetCode;
    private int provincePosition;
    private int cityPosition;
    private int countyPosition;
    private int streetPosition;
    private Context context;
    private TextView tv_dialoging;//加载动画
    private TextView tv_warning;//警告提示
    DelDialog confirmDialog=null;

    @Override
    protected void setOnCreateContentView() {
        setContentView(R.layout.activity_text_frame);
        context=TextFrameActivity.this;
        LogWk("onCreate");
    }
    protected void initView() {
        LogWk("initView");
        tv_selector_area = (TextView) findViewById(R.id.tv_selector_area);
        tv_dialoging = (TextView) findViewById(R.id.tv_dialoging);
        tv_warning = (TextView) findViewById(R.id.tv_warning);
    }
    @Override
    protected void initData() {
        LogWk("initData");
    }
    protected void initClick() {
        LogWk("initClick");
        tv_selector_area.setOnClickListener(this);
        tv_dialoging.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showLoad();
            }
        });
        tv_warning.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DelDialog.Builder customBuilder = new DelDialog.Builder(context);
                customBuilder.setPositiveListener(new DelDialog.Builder.ClickListener() {
                    @Override
                    public void click() {
                        ToastUtils.showShortToast(context,"确定");
                        confirmDialog.dismiss();
                    }
                }).setNegativeListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        confirmDialog.dismiss();
                    }
                });
                confirmDialog = customBuilder.create();
                confirmDialog.show();
            }
        });
    }
    @Override
    public void onClick(View view) {
        if (dialog != null) {
            dialog.show();
        } else {
            dialog = new BottomDialog(this);
            dialog.setOnAddressSelectedListener(this);
            dialog.setDialogDismisListener(this);
            dialog.setTextSize(14);//设置字体的大小
            dialog.setIndicatorBackgroundColor(android.R.color.holo_red_dark);//设置指示器的颜色
            dialog.setTextSelectedColor(android.R.color.holo_red_dark);//设置字体获得焦点的颜色
            dialog.setTextUnSelectedColor(android.R.color.holo_red_dark);//设置字体没有获得焦点的颜色
//            dialog.setDisplaySelectorArea("31",1,"2704",1,"2711",0,"15582",1);//设置已选中的地区
            dialog.setSelectorAreaPositionListener(this);
            dialog.show();
        }
    }

    @Override
    public void onAddressSelected(Province province, City city, County county, Street street) {
        provinceCode = (province == null ? "" : province.code);
        cityCode = (city == null ? "" : city.code);
        countyCode = (county == null ? "" : county.code);
        streetCode = (street == null ? "" : street.code);
//        LogUtil.d("数据", "省份id=" + provinceCode);
//        LogUtil.d("数据", "城市id=" + cityCode);
//        LogUtil.d("数据", "乡镇id=" + countyCode);
//        LogUtil.d("数据", "街道id=" + streetCode);

        Log.d("数据", "省份id=" + provinceCode);
        Log.d("数据", "城市id=" + cityCode);
        Log.d("数据", "乡镇id=" + countyCode);
        Log.d("数据", "街道id=" + streetCode);
        Log.d("", "onAddressSelected: ");
        String s = (province == null ? "" : province.name) + (city == null ? "" : city.name) + (county == null ? "" : county.name) +
                (street == null ? "" : street.name);
        tv_selector_area.setText(s);
        if (dialog != null) {
            dialog.dismiss();
        }
//        getSelectedArea();
    }
    @Override
    public void dialogclose() {
        if(dialog!=null){
            dialog.dismiss();
        }
    }
    @Override
    public void selectorAreaPosition(int provincePosition, int cityPosition, int countyPosition, int streetPosition) {
        this.provincePosition = provincePosition;
        this.cityPosition = cityPosition;
        this.countyPosition = countyPosition;
        this.streetPosition = streetPosition;
        LogUtil.d("数据", "省份位置=" + provincePosition);
        LogUtil.d("数据", "城市位置=" + cityPosition);
        LogUtil.d("数据", "乡镇位置=" + countyPosition);
        LogUtil.d("数据", "街道位置=" + streetPosition);
    }
}
